package tool

import play.api.data.Forms._
import play.api.data.JodaForms.jodaDate
import play.api.data._

/**
 * Created by yz on 2018/7/17
 */

import tool.Pojo._

object FormTool {

  val missionNameCheckForm = Form(
    mapping(
      "missionName" -> text,
      "kind" -> text,
    )(MissionNameCheckData.apply)(MissionNameCheckData.unapply)
  )

  val fileNameForm = Form(
    mapping(
      "fileName" -> text
    )(FileNameData.apply)(FileNameData.unapply)
  )

  val searchForm = Form(
    mapping(
      "missionName" -> optional(text),
      "missionIntro" -> optional(text),
      "startDate" -> optional(jodaDate),
      "endDate" -> optional(jodaDate)
    )(SearchData.apply)(SearchData.unapply)
  )

  val sampleSearchForm = Form(
    mapping(
      "id" -> text,
      "indexId" -> text,
      "sampleIntro" -> text,
      "gender" -> text,
      "kind" -> text,
      "comment" -> text,
      "updateMission" -> text,
      "startDate" -> optional(jodaDate),
      "endDate" -> optional(jodaDate)
    )(SampleSearchData.apply)(SampleSearchData.unapply)
  )

  val missionForm = Form(
    mapping(
      "missionName" -> text,
      "lane" -> text,
      "id" -> text,
      "gender" -> text,
      "kind" -> text
    )(MissionData.apply)(MissionData.unapply)
  )

  val sampleIdForm = Form(
    mapping(
      "id" -> text
    )(SampleIdData.apply)(SampleIdData.unapply)
  )

  val kindForm = Form(
    mapping(
      "kind" -> optional(text)
    )(KindData.apply)(KindData.unapply)
  )

  val kindSomeForm = Form(
    mapping(
      "kind" -> text
    )(KindSomeData.apply)(KindSomeData.unapply)
  )

  val missionNameForm = Form(
    mapping(
      "missionName" -> text
    )(MissionNameData.apply)(MissionNameData.unapply)
  )

  val idForm = Form(
    mapping(
      "id" -> text
    )(IdData.apply)(IdData.unapply)
  )

  val imageTypeForm = Form(
    mapping(
      "imageType" -> text
    )(ImageTypeData.apply)(ImageTypeData.unapply)
  )

  val idsForm = Form(
    mapping(
      "ids" -> seq(text)
    )(IdsData.apply)(IdsData.unapply)
  )

  val keywordForm = Form(
    mapping(
      "keyword" -> text
    )(KeywordData.apply)(KeywordData.unapply)
  )

  val advancedFilterForm = Form(
    mapping(
      "junctionTypes" -> optional(list(text)),
      "annotations" -> optional(list(text)),
      "tumorTypes" -> optional(list(text)),
      "chr" -> optional(text),
      "start" -> optional(number),
      "end" -> optional(number)
    )(AdvancedFilterData.apply)(AdvancedFilterData.unapply)
  )

  val geneSymbolForm = Form(
    mapping(
      "geneSymbol" -> text
    )(GeneSymbolData.apply)(GeneSymbolData.unapply)
  )

  val geneModalForm = Form(
    mapping(
      "geneSymbol" -> text,
      "method" -> text,
    )(GeneModalData.apply)(GeneModalData.unapply)
  )

  val tcgaForm = Form(
    mapping(
      "junctionId" -> text,
      "logScale" -> text
    )(TcgaData.apply)(TcgaData.unapply)
  )

  val survivalForm = Form(
    mapping(
      "junctionId" -> text,
      "kind" -> text,
      "methods" -> text,
      "groupCutoff" -> text
    )(SurvivalData.apply)(SurvivalData.unapply)
  )

  val base64Form = Form(
    mapping(
      "base64" -> text
    )(Base64Data.apply)(Base64Data.unapply)
  )

  val boxplotForm = Form(
    mapping(
      "junctionId" -> text,
      "logScale" -> optional(text),
      "kinds" -> list(text)
    )(BoxplotData.apply)(BoxplotData.unapply)
  )

  val dirForm = Form(
    mapping(
      "dir" -> text
    )(DirData.apply)(DirData.unapply)
  )

  val junctionIdForm = Form(
    mapping(
      "junctionId" -> text
    )(JunctionIdData.apply)(JunctionIdData.unapply)
  )

  val junctionIdsForm = Form(
    mapping(
      "junctionIds" -> list(text)
    )(JunctionIdsData.apply)(JunctionIdsData.unapply)
  )

  val detailForm = Form(
    mapping(
      "junctionId" -> text,
      "kind" -> text
    )(DetailData.apply)(DetailData.unapply)
  )

  val batchMissionForm = Form(
    mapping(
      "missionIntro" -> text,
      "dataType" -> text,
      "splitDir" -> text,
      "serverGzFile" -> text,
      "isCover" -> optional(boolean)
    )(BatchMissionData.apply)(BatchMissionData.unapply)
  )

  val serverDirForm = Form(
    mapping(
      "splitDir" -> text
    )(ServerDirData.apply)(ServerDirData.unapply)
  )

  val adminSetForm = Form(
    mapping(
      "gzPath" -> text,
    )(AdminSetData.apply)(AdminSetData.unapply)
  )

  val nodeForm = Form(
    mapping(
      "id" -> text,
    )(NodeData.apply)(NodeData.unapply)
  )

  val missionIdForm = Form(
    mapping(
      "missionId" -> number
    )(MissionIdData.apply)(MissionIdData.unapply)
  )

  val siteNamesForm = Form(
    mapping(
      "siteNames" -> seq(text)
    )(SiteNamesData.apply)(SiteNamesData.unapply)
  )

  val sexForm = Form(
    mapping(
      "sex" -> text
    )(SexData.apply)(SexData.unapply)
  )

  val compareMissionForm = Form(
    mapping(
      "userId" -> number,
      "missionName" -> text,
      "sample1" -> text,
      "sample2" -> text
    )(CompareMissionData.apply)(CompareMissionData.unapply)
  )

  val kitNameForm = Form(
    mapping(
      "kitName" -> text
    )(KitNameData.apply)(KitNameData.unapply)
  )

  val sampleIdsForm = Form(
    mapping(
      "ids" -> seq(text)
    )(SampleIdsData.apply)(SampleIdsData.unapply)
  )

  val pageForm = Form(
    mapping(
      "limit" -> number,
      "offset" -> number,
      "search" -> optional(text),
      "geneTypes" -> optional(list(text)),
      "junctionTypes" -> optional(list(text)),
      "annotations" -> optional(list(text)),
      "tumorTypes" -> optional(list(text)),
      "geneSymbols" -> optional(list(text)),
      "order" -> text,
      "sort" -> optional(text),
      "tumorTypesMethod" -> text,
    )(PageData.apply)(PageData.unapply)
  )

  val queryPageForm = Form(
    mapping(
      "search" -> optional(text),
      "geneTypes" -> optional(list(text)),
      "junctionTypes" -> optional(list(text)),
      "annotations" -> optional(list(text)),
      "tumorTypes" -> optional(list(text))
    )(QueryPageData.apply)(QueryPageData.unapply)
  )

  val browseForm = Form(
    mapping(
      "geneTypes" -> optional(list(text))
    )(BrowseData.apply)(BrowseData.unapply)
  )


}
